<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{
    /**
     * 企业网站主页
     */
    public function index(){

        // 获取模型
        $siteModel = M('Site');

        if($_SERVER['HTTP_HOST'] == 'www.ds.com'){
            // 通过域名解析站点
            echo "<script>window.location = '/ds.html';</script>";
        }
        else {
            // 通过GET参数解析
            $siteInfo = $siteModel->where(['domain' => $_SERVER['HTTP_HOST']])->select();
            // 查找站点信息
            if (empty($siteInfo))
                $this->error('404 您所访问的页面不存在');
            $siteInfo = $siteInfo[0];
        }
        //获取广告数据
        $ad_sense = M("ad_sense");
        $ad = M("ad");

        $ad_sense_left = $ad_sense->where(['sid'=>$siteInfo['id'],'position'=>'left'])->find();
        $ad_sense_left['info'] = $ad->where(['aid'=>$ad_sense_left['id']])->find();


        $ad_sense_right = $ad_sense->where(['sid'=>$siteInfo['id'],'position'=>'right'])->find();
        $ad_sense_right['info'] = $ad->where(['aid'=>$ad_sense_right['id']])->find();

        $this->assign('ad_sense_left',$ad_sense_left);
        $this->assign('ad_sense_right',$ad_sense_right);

        $this->assign('SiteInfo', $siteInfo);
        $this->theme($siteInfo['skin'])->display('index');


    }

    /**
     * 关于我们页面
     */
    public function about(){
            // 获取模型
        $siteModel = M('Site');

        if($_SERVER['HTTP_HOST'] == 'www.ds.com'){
            // 通过域名解析站点
            echo "<script>window.location = '/ds.html';</script>";
        }
        else {
            // 通过GET参数解析
            $siteInfo = $siteModel->where(['domain' => $_SERVER['HTTP_HOST']])->select();
            // 查找站点信息
            if (empty($siteInfo))
                $this->error('404 您所访问的页面不存在');
            $siteInfo = $siteInfo[0];
        }

        //获取广告数据
        $ad_sense = M("ad_sense");
        $ad = M("ad");

        $ad_sense_left = $ad_sense->where(['sid'=>$siteInfo['id'],'position'=>'left'])->find();
        $ad_sense_left['info'] = $ad->where(['aid'=>$ad_sense_left['id']])->find();


        $ad_sense_right = $ad_sense->where(['sid'=>$siteInfo['id'],'position'=>'right'])->find();
        $ad_sense_right['info'] = $ad->where(['aid'=>$ad_sense_right['id']])->find();

        $this->assign('ad_sense_left',$ad_sense_left);
        $this->assign('ad_sense_right',$ad_sense_right);


        $this->assign('SiteInfo', $siteInfo);
        $this->theme($siteInfo['skin'])->display('about');

    }
    /*
     * 新闻中心
     */
    public function news(){
        //获取新闻数据
        $news = M('news');
        $list=$news->select();
        $this -> assign("list",$list);

        // 获取模型
        $siteModel = M('Site');

        if($_SERVER['HTTP_HOST'] == 'www.ds.com'){
            // 通过域名解析站点
            echo "<script>window.location = '/ds.html';</script>";
        }
        else {
            // 通过GET参数解析
            $siteInfo = $siteModel->where(['domain' => $_SERVER['HTTP_HOST']])->select();
            // 查找站点信息
            if (empty($siteInfo))
                $this->error('404 您所访问的页面不存在');
            $siteInfo = $siteInfo[0];
        }
        $this->assign('SiteInfo', $siteInfo);
        $this->theme($siteInfo['skin'])->display('news');





    }
    public function products(){
        // 获取模型
        $siteModel = M('Site');

        if($_SERVER['HTTP_HOST'] == 'www.ds.com'){
            // 通过域名解析站点
            echo "<script>window.location = '/ds.html';</script>";
        }
        else {
            // 通过GET参数解析
            $siteInfo = $siteModel->where(['domain' => $_SERVER['HTTP_HOST']])->select();
            // 查找站点信息
            if (empty($siteInfo))
                $this->error('404 您所访问的页面不存在');
            $siteInfo = $siteInfo[0];
        }

        $this->assign('SiteInfo', $siteInfo);
        $this->theme($siteInfo['skin'])->display('products');

    }
    public function messages(){
        // 获取模型
        $siteModel = M('Site');

        if($_SERVER['HTTP_HOST'] == 'www.ds.com'){
            // 通过域名解析站点
            echo "<script>window.location = '/ds.html';</script>";
        }
        else {
            // 通过GET参数解析
            $siteInfo = $siteModel->where(['domain' => $_SERVER['HTTP_HOST']])->select();
            // 查找站点信息
            if (empty($siteInfo))
                $this->error('404 您所访问的页面不存在');
            $siteInfo = $siteInfo[0];
        }

        $this->assign('SiteInfo', $siteInfo);
        $this->theme($siteInfo['skin'])->display('messages');

    }
    public function contact(){
        // 获取模型
        $siteModel = M('Site');

        if($_SERVER['HTTP_HOST'] == 'www.ds.com'){
            // 通过域名解析站点
            echo "<script>window.location = '/ds.html';</script>";
        }
        else {
            // 通过GET参数解析
            $siteInfo = $siteModel->where(['domain' => $_SERVER['HTTP_HOST']])->select();
            // 查找站点信息
            if (empty($siteInfo))
                $this->error('404 您所访问的页面不存在');
            $siteInfo = $siteInfo[0];
        }

        $this->assign('SiteInfo', $siteInfo);
        $this->theme($siteInfo['skin'])->display('contact');

    }
    public function content(){

        $news = M('news');

        $list=$news->where(['id'=>$_GET['id']])->select();

        $this -> assign("list",$list);

        $this->theme('Blue')->display();
    }
}